package yxy.game.pm2.command.therionHunting;


import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TherionHuntingMessage;
import yxy.game.pm2.module.therionHunting.TherionHandle;
import yxy.game.pm2.module.therionHunting.TherionModule;
import yxy.game.pm2.module.therionHunting.TherionPlayerModule;

import java.util.HashMap;

/**
 * @name CMD_TherionChallengeRecord
 * @author wrs
 * @descrition 神兽挑战记录
 * @since 2022-06-10
 */
@MessageType(proto = Command.TherionChallengeRecord ,classtype = TherionHuntingMessage.TherionChallengeRecordRequest.class)
public class CMD_TherionChallengeRecord extends Command<TherionHuntingMessage.TherionChallengeRecordRequest> {

    @Override
    public void execute(MessageSource messageSource, TherionHuntingMessage.TherionChallengeRecordRequest request) throws Exception {
        String playerCode = messageSource.getTag();
        int gameType = request.getGameType();

        TherionHuntingMessage.TherionChallengeRecordResponse.Builder response = TherionHuntingMessage.TherionChallengeRecordResponse.newBuilder();

        try {
            TherionHandle handle = new TherionHandle();

            HashMap<Integer, HashMap<Integer, yxy.game.pm2.module.therionHunting.TherionChallengeRecord>> challengeRecords = TherionPlayerModule.get(playerCode).getChallengeRecords();
            if (challengeRecords == null){
                send(messageSource,response, Result.DataError);
                return;
            }

            switch (gameType){
                case TherionModule.THERION_LOCAL:
                    //本服挑战记录：青龙，白虎，朱雀，玄武
                    HashMap<Integer, yxy.game.pm2.module.therionHunting.TherionChallengeRecord> map1 = challengeRecords.get(TherionModule.THERION_LOCAL);
                    handle.packRecords(map1,response);
                    break;

                case TherionModule.THERION_CROSS:
                    //跨服挑战记录：青龙，白虎，朱雀，玄武
                    HashMap<Integer, yxy.game.pm2.module.therionHunting.TherionChallengeRecord> map2 = challengeRecords.get(TherionModule.THERION_CROSS);
                    handle.packRecords(map2,response);
                    break;

                case TherionModule.THERION_WORLD:
                    //世界挑战记录：青龙，白虎，朱雀，玄武
                    HashMap<Integer, yxy.game.pm2.module.therionHunting.TherionChallengeRecord> map3 = challengeRecords.get(TherionModule.THERION_WORLD);
                    handle.packRecords(map3,response);
                    break;
                default:
                    send(messageSource,response, Result.DataError);
                    break;
            }

            send(messageSource,response, Result.Success);
        }catch (Exception e){
            e.printStackTrace();
            send(messageSource,response, Result.DataError);
        }

    }

    private void send(MessageSource messageSource, TherionHuntingMessage.TherionChallengeRecordResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
